import { errLog } from "../util/log";
import { jobGoto } from "./goto"

export const jobStructure = {
    /**
     * 
     * @param {Creep} creep 
     * @param {RoomPosition} pos 
     * @param {(Creep)=>CreepActionReturnCode} callback 
     */
    run(creep, pos, callback, ...args){
        if(!creep.pos.isEqualTo(pos)){
            try{
                callback(creep,...args);
            }catch(e){
                errLog(e);
            }
            return jobGoto.run(creep, [{pos:pos}]);
        }
        return callback(creep,...args);
    }
}